package com.windmill.bean;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;

public class GroupUser implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long qq;
	private long groupId;//群号
	private List<String> cardNames;//历史昵称
	private double money;//
	private int contribution;//贡献
	private int luckValue;
	private List<Goods> bagList;
	private Date dayReg;
	private int vip;
	private Chat chat;
	public GroupUser(){
		this.cardNames = new ArrayList<String>();
		this.bagList = new ArrayList<Goods>();
		this.chat = new Chat();
	}
	public String toString(){
		DecimalFormat    df   = new DecimalFormat("######0.0");
		return 	getCardName()+"("+qq+")的名片："
				+"\n贡　献："+contribution+"  幸运值："+(luckValue+100)
				+"\n魔法币："+df.format(money)+"  签到："+(isReg()?"已":"未")+"签到";
//				+"\n特　权："+vip+"级";
//				+"\n物　品："+bagList.toArray();
	}

	public long getQq() {
		return qq;
	}
	public void setQq(long qq) {
		this.qq = qq;
	}
	public long getGroupId() {
		return groupId;
	}
	public void setGroupId(long groupId) {
		this.groupId = groupId;
	}
	public List<String> getCardNames() {
		return cardNames;
	}
	public void setCardNames(List<String> cardNames) {
		this.cardNames = cardNames;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	public int getContribution() {
		return contribution;
	}
	public void setContribution(int contribution) {
		this.contribution = contribution;
	}
	public List<Goods> getBagList() {
		return bagList;
	}
	public void setBagList(List<Goods> bagList) {
		this.bagList = bagList;
	}
	public int getVip() {
		return vip;
	}
	public void setVip(int vip) {
		this.vip = vip;
	}
	public Date getDayReg() {
		return dayReg;
	}
	public void setDayReg(Date dayReg) {
		this.dayReg = dayReg;
	}
	public int getLuckValue() {
		return luckValue;
	}
	public void setLuckValue(int luckValue) {
		this.luckValue = luckValue;
	}
	public Chat getChat() {
		return chat;
	}
	public void setChat(Chat chat) {
		this.chat = chat;
	}
//	private String format(Date date) {
//		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
//		return fmt.format(date);
//	}
	public void setCardName(String nickname) {
		if(this.cardNames.contains(nickname)){
			cardNames.remove(nickname);
		}
		cardNames.add(0, nickname);
	}
	public String getCardName() {	
		if(cardNames.get(0)==null)cardNames.remove(0);
		return cardNames.size()>0?cardNames.get(0):this.qq+"";
	}
	public void addMoney(double money) {
		this.money += money; 
	}
	private Calendar nowCal = new GregorianCalendar(),
			lastCal = new GregorianCalendar();
	private boolean isReg(){
		boolean flag = false;
		if(dayReg!=null){			
			nowCal.setTime(new Date());
			lastCal.setTime(this.dayReg);		
			flag = nowCal.get(Calendar.DAY_OF_YEAR)==lastCal.get(Calendar.DAY_OF_YEAR);					
		}
		return flag;
	}
	public String dayReg() {
		String result = getCardName();
		if(!isReg()){
			Random r = new Random();
			int money = r.nextInt(5)+1;
			addMoney(money);
			this.contribution++;
			dayReg = new Date();
			result += "签到成功！您获得"+money+"个魔法币。";
		}else{
			result += "您今天已经签到了！";
		}
		return result;
	}
}
